package kr.pe.johnkim.carrotpoint.mobile.controller;

import kr.pe.johnkim.carrotpoint.mobile.domain.CarrotPointMemberPointLog;
import kr.pe.johnkim.carrotpoint.mobile.service.CarrotPointMemberPointLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Carrot Point 사용자 포인트 관련 controller 클래스 이다.
 *
 * @author : John_Kim <cale9797@gmail.com>
 * @date : 13. 2. 6.
 */
@Controller
@RequestMapping(value = "/carrotPointMemberPointLogController")
public class CarrotPointMemberPointLogController {
    // SLF4J Logging
    private Logger logger = LoggerFactory.getLogger(CarrotPointMemberPointLogController.class);

    @Autowired
    private CarrotPointMemberPointLogService carrotPointMemberPointLogService;

    /**
     * 포인트 아이디로 포인트 로그 목록을 가져 온다.
     *
     * @param carrotPointMemberPointLog
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getMemberPointLogList", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public List<CarrotPointMemberPointLog> getMemberPointLogList
            (@RequestBody CarrotPointMemberPointLog carrotPointMemberPointLog) throws Exception {
        logger.info("getMemberPointLogList");

        return carrotPointMemberPointLogService.getMemberPointLogList(carrotPointMemberPointLog);
    }

    /**
     * 포인트 로그 내용을 가져 온다.
     *
     * @param carrotPointMemberPointLog
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getMemberPointLogInformation", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public CarrotPointMemberPointLog getMemberPointLogInformation
            (@RequestBody CarrotPointMemberPointLog carrotPointMemberPointLog) throws Exception {
        logger.info("getMemberPointLogInformation");

        return carrotPointMemberPointLogService.getMemberPointLogInformation(carrotPointMemberPointLog);
    }

    /**
     * 포인트 로그 활성화 여부를 업데이트 한다.
     *
     * @param carrotPointMemberPointLog
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/updateMemberPointLogActivateYn", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public CarrotPointMemberPointLog updateMemberPointLogActivateYn
            (@RequestBody CarrotPointMemberPointLog carrotPointMemberPointLog) throws Exception {
        logger.info("updateMemberPointLogActivateYn");

        CarrotPointMemberPointLog result = new CarrotPointMemberPointLog();

        try {
            carrotPointMemberPointLogService.updateMemberPointLogActivateYn(carrotPointMemberPointLog);
            result.setResult("SUCCESS");
            logger.info("success to update member point log activateYn.");
        } catch (Exception e) {
            result.setResult("FAIL");
            logger.info("fail to update member point log activateYn.");
        }

        return result;
    }
}
